package state.socket;

import java.util.Hashtable;

import state.socket.DataPackage;
import state.socket.DataReceiveListener;

public class FlowManager extends Hashtable {
  private static final long serialVersionUID = 1L;

  public boolean isMatch(int header) {
    return get(new Integer(header)) != null;
  }
  
  public void execute(DataPackage dataPackage) {
    DataReceiveListener listener = (DataReceiveListener) get(new Integer(dataPackage.getHeader()));
    if (listener != null) {
      dataPackage.nextString();
      dataPackage.nextInt();
      dataPackage.setHeader(dataPackage.nextInt());
      listener.onRecieveData(dataPackage);
    }
  }
  
  public static DataPackage createFlowPackage(int flowHeader, int header) {
    DataPackage dataPackage = new DataPackage(flowHeader);
    dataPackage.putString("header");
    dataPackage.putInt(header);
    return dataPackage;
  }
}
